<template>
  <div class="receive">
    <info :data='data' :type="data.type"></info>
    <service-content :data="data" @bookNow='bookNow'></service-content>
    <book-now :data='data' @bookNow='bookNow'></book-now>
  </div>
</template>

<script>
  import {mapActions} from 'vuex'
  import { Toast } from 'mint-ui'
  // import { Toast, MessageBox } from 'mint-ui'
  import info from './Info'
  import serviceContent from './ServiceContent'
  import bookNow from './BookNow'
  // import axios from 'axios'
  export default {
    name: 'receive',
    components: {
      info,
      serviceContent,
      bookNow
    },
    data () {
      return {
        data: {
          type: 'receive',
          inOrOut: 'in',
          airport: '',
          terminal: '',
          flightNum: '',
          serviceTime: '',
          airportType: ''
        }
      }
    },
    mounted () {
      this.getCookie('ylUserInfo').then((token) => {
        // this.token = '7b9b29d4-791b-40f8-bfc8-8e49a9ed7884'
        this.token = token
      })
    },
    watch: {
      'data.airportType' (newVal, oldVal) {
        console.log(newVal)
      }
    },
    methods: {
      // 映射State
      ...mapActions([
        'getCookie', 'wxLogin'
      ]),
      bookNow () {
        if (!this.token) {
          Toast({
            message: '请先登录',
            position: 'center',
            duration: 500
          })
          setTimeout(() => {
            let wxInfo = {
              state: '',
              url: this.$route.fullPath.replace('/', '')
            }
            wxInfo.url = wxInfo.url ? wxInfo.url : 'receive'
            this.wxLogin(wxInfo)
          }, 500)
          return false
        }
        if (this.data.terminal === '') {
          Toast({
            message: '请选择航站楼',
            position: 'center',
            duration: 500
          })
          return false
        }
        if (this.data.flightNum === '') {
          Toast({
            message: '请填写航班号',
            position: 'center',
            duration: 500
          })
          return false
        }
        if (this.data.airportType === '') {
          Toast({
            message: '请填写航班类型',
            position: 'center',
            duration: 500
          })
          return false
        }
        if (this.data.serviceTime === '') {
          Toast({
            message: '请选择服务时间',
            position: 'center',
            duration: 500
          })
          return false
        }
        // window.location.replace('/sr/confirm/#/confirm/vip/' + encodeURIComponent(this.data.terminal.id + '&' + this.data.flightNum + '&' + this.data.serviceTime))
        window.location.replace('/sr/order/#/confirm/vip/' + encodeURIComponent(this.data.airportType.serviceId + '&' + this.data.terminal.id + '&' + this.data.flightNum + '&' + this.data.serviceTime))
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang='less'>
</style>
